package com.housekeeper.manage.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.housekeeper.api.manage.dtos.bill.OrderBillDto;
import com.housekeeper.api.manage.dtos.bill.OwnerBillDetailDto;
import com.housekeeper.api.manage.dtos.bill.OwnerBillDto;
import com.housekeeper.api.manage.dtos.bill.OwnerPageListDto;
import com.housekeeper.api.manage.service.BillService;
import com.housekeeper.common.response.PageResult;
import com.housekeeper.common.response.ResponseEnum;
import com.housekeeper.common.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:王子
 * 账单管理模块
 */
@RestController
@RequestMapping("/bill")
public class BillController {
    @Autowired
    private BillService billService;

    @GetMapping("/owner")
    public Result<List<OwnerBillDto>> getOwnerBill(@RequestBody OwnerPageListDto ownerPageListDto){
        PageInfo pageInfo = billService.getOwnerBill(ownerPageListDto);
        PageResult pageResult = new PageResult();
        pageResult.setData(pageInfo.getList());
        pageResult.setCurrentPage(ownerPageListDto.getCurrentPage());
        pageResult.setSize(ownerPageListDto.getSize());
        pageResult.setTotal(Integer.parseInt(String.valueOf(pageInfo.getTotal())));
        return PageResult.okResult(pageResult);
    }
    @GetMapping("/owner/detail/{billCode}")
    public Result<OwnerBillDetailDto> getOwnerBillDetail(@PathVariable Long billCode){
        OwnerBillDetailDto ownerBillDetailDto = billService.getOwnerBillDetail(billCode);
        return Result.okResult(ownerBillDetailDto);
    }
    @PostMapping("/genbill")
    public Result generateBill(@RequestBody OrderBillDto orderBillDto){
        billService.generateBill(orderBillDto);
        return Result.okResult(ResponseEnum.SUCCESS);
    }

}
